//
//  XSJoinViewController.m
//  MeiLiYiChu
//
//  Created by mac on 16/2/29.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "XSJoinViewController.h"
#import "UMSocial.h"
#import "XSJoin.h"
@interface XSJoinViewController ()

@end

@implementation XSJoinViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title =@"美丽衣橱";
    
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [XSHTTPManager getJoinPlistWithComplection:^(NSMutableArray *urlArr) {
        _urlArr =urlArr;
        
        [self createView];
    }];

//    [_tabBar setHidden:YES];
}
-(void)viewDidDisappear:(BOOL)animated
{
    _tabBar.hidden =NO;
}
-(void)createView
{
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.bounds =CGRectMake(0, 0, 40, 40);
    
    [button1 setBackgroundImage:[UIImage imageNamed:@"button_back-iOS7"] forState:UIControlStateNormal];
    
    [button1 addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *item =[[UIBarButtonItem alloc]initWithCustomView:button1];
    self.navigationItem.leftBarButtonItem =item;
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.bounds =CGRectMake(0, 0, 50, 30);
    [button2 setTitle:@"分享" forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor magentaColor] forState:UIControlStateNormal];
    button2.backgroundColor =[UIColor whiteColor];
    [button2 addTarget:self action:@selector(share) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * item1 =[[UIBarButtonItem alloc]initWithCustomView:button2];
    self.navigationItem.rightBarButtonItem =item1;
    
    UIImageView * image =[[UIImageView alloc]initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, 50)];
//    image.image =[UIImage imageNamed:<#(nonnull NSString *)#>]
    [self.view addSubview:image];
    
    XSJoin * join =_urlArr[0];
    UILabel * lab =[[UILabel alloc]init];
    lab.center =CGPointMake(image.center.x, image.frame.size.height/2);
    lab.bounds =CGRectMake(0, 0, 200, 50);
    lab.text =join.title;
    lab.textColor =[UIColor redColor];
    lab.textAlignment =NSTextAlignmentCenter;
    [image addSubview:lab];
    
//    [self.view bringSubviewToFront:image];
    
    UIView * view =[[UIView alloc]init];
    
    view.backgroundColor =[UIColor whiteColor];
    [self.view addSubview:view];
//    [self.view bringSubviewToFront:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        
        make.bottom.offset(0);
        make.height.equalTo(@50);
    }];

    UILabel * lab1 =[[UILabel alloc]init];
    lab1.text =join.deposit_message;

    
    [view addSubview:lab1];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.right.offset(0);
        
        make.bottom.offset(0);
        make.height.equalTo(@50);
    }];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.backgroundColor =[UIColor redColor];
    [button setTitle:@"立即加盟" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(join) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];

    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(5);
        make.bottom.offset(-5);
        make.right.offset(-10);
        make.width.equalTo(@100);
        
        make.height.equalTo(@40);
    }];
    UIScrollView * scroll =[[UIScrollView alloc]init];
    scroll.frame = CGRectMake(0, image.frame.origin.y, self.view.bounds.size.width, self.view.bounds.size.height-image.frame.origin.y);
    scroll.contentSize =CGSizeMake(scroll.frame.size.width, scroll.frame.size.height * join.array.count);
    
    for (int i =0; i <join.array.count; i++)
    {
        UIImageView * image =[[UIImageView alloc]init];
        [image sd_setImageWithURL:[NSURL URLWithString:join.array[i]]];
       
        image.frame =CGRectMake(0, i*scroll.frame.size.height, scroll.frame.size.width, scroll.frame.size.height);
        [scroll addSubview:image];
    }
    scroll.pagingEnabled =YES;
    scroll.bounces =YES;
    
    [self.view addSubview:scroll];
    [self.view sendSubviewToBack:scroll];
}
-(void)join
{
    
}
-(void)back
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
-(void)share
{
    //分享
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"56cc4f11e0f55a8a04002ff8"
                                      shareText:@"你好,早安!"
                                     shareImage:[UIImage imageNamed:@"icon"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,nil]
                                       delegate:self];
    
}
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
